<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="所在城市：">
          <el-select v-model="formInline.cities" filterable clearable>
              <el-option v-for="(item,index) in cityJson" :key="index" :label="item.name" :value="item.code"></el-option>
            </el-select>
          <!-- <city-select v-model="formInline.cities"></city-select> -->
        </el-form-item>
        <el-form-item label="牙齿问题：">
          <el-select v-model="formInline.troubles" filterable clearable>
            <el-option v-for="(item,index) in troubleList" :key="index" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属平台：">
          <PlatformSelect v-model="formInline.platforms"></PlatformSelect>
        </el-form-item>
        <el-form-item label="查询时间：">
          <el-date-picker v-model="formInline.orderTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关键词：">
          <el-input v-model="formInline.term" placeholder="请输入关键词"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- 操作区域 开始 -->
      <div class="action_box">
        <!-- <auth-button uid="1060203" type="primary" size="small" @click.native="addHospital()">新增医生</auth-button> -->
        <el-button type="primary" size="small" :loading="eloading" @click="downloadExcel">筛选结果导出</el-button>
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="phone" label="手机号码" show-overflow-tooltip />
        <el-table-column prop="cityName" label="所在城市" show-overflow-tooltip />
        <el-table-column prop="trouble" label="牙齿问题" show-overflow-tooltip />
        <el-table-column prop="platform" label="所属平台" show-overflow-tooltip />
        <el-table-column prop="createdDate" label="查询时间" show-overflow-tooltip />
        <el-table-column prop="ip" label="查询ip" show-overflow-tooltip />
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->
  </div>
</template>
  
  <script>
import { GETCITYOPTIONS } from "@/http/system";
import { showToast, showModal, deepClone } from "@/common/util";
import TabHospital from "@/components/hospital";
import { GETHOSPITALSEARCH, DELETEHOSPITALINFO } from "@/http/hospital";
import { GET_QUOTATION_SEARCH,DOWNLOAD_QUOTATION_EXPORT } from "@/http/consumer";
import PlatformSelect from '@/components/select/platform.vue'
import cityJson from '@/assets/json/city.json'
import {GET_TROUBLE_OPTION} from '@/http/configuration'
export default {
  components: {
    TabHospital,
    PlatformSelect
  },
  data() {
    return {
      formInline: { },
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      loading: false,
      eloading:false,
      troubleList:[],
      cityJson
    };
  },
  mounted() {
    this.getList();
    this.getTrouble()
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = { };
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = deepClone(this.formInline);
      let m = oParams.orderTime || []
      if(m && m.length){
        oParams.queryBeginTime = m[0]
        oParams.queryEndTime = m[1]
      }

      delete oParams.orderTime
      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_QUOTATION_SEARCH(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 删除
    removeHospital(row) {
      let _this = this;
      showModal({
        message: `确定删除${row.name}吗？`,
        showCancelButton: true,
        success: function () {
          DELETEHOSPITALINFO({ id: row.id }).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "删除成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },

    // 导出excel
    downloadExcel() {
      let _this = this;
      let o = deepClone(_this.formInline);
      let m = Object.keys(o);
      if (m.length > 0) {
        showModal({
          message: "确定是否导出筛选条件下面所有查询价格列表?",
          showCancelButton: true,
          type: "warning",
          success: function () {
            _this.dowloadExcelFile();
          },
        });
        return false;
      }
      showToast({
        message: "请选择筛选条件后再导出",
      });

      //_this.dowloadExcelFile();
    },

    // 下载excel
    dowloadExcelFile() {
      let _this = this;
      let oParams = _this.getParams();
      let options = {};

      delete oParams.pageNumber;
      delete oParams.pageSize;

      options.method = "GET";
      options.data = oParams;
      options.url = DOWNLOAD_QUOTATION_EXPORT;
      options.fileName = "查询价格列表.xlsx";
      _this.eloading = true;
      _this.$exportExcel(options).then((res) => {
        _this.eloading = false;
      });
    },

    // 获取口腔问题
    getTrouble(){
      GET_TROUBLE_OPTION().then(res => {
        this.troubleList = res.data || []
      })
    },

    // 搜索
    onSearch(){
      this.pageNumber = 1;
      this.getList()
    }

  },
};
</script>
  
  <style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
  